package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.itheima.dao.CustomerDao;
import com.itheima.domain.Customer;
import com.itheima.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ClassName:LinkManServiceImpl
 * Package:com.itheima.service.impl
 * Description:
 * Date:2020/3/16 23:46
 * User: snow
 */
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
	@Autowired
	private CustomerDao customerDao;

	/**
	 * 查找所有用户
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Customer> findAll() throws Exception {
		//查询客户列表
		return customerDao.findAll();
	}
	/**
	 * 查找所有用户
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Customer> findAll(int page,int size) throws Exception {
		/**
		 * //参数配置
		 * pageNum 页码值   pageSize  每页最大值
		 */
		PageHelper.startPage(page,size);
		//查询客户列表
		return customerDao.findAll();
	}

	/**
	 * 模糊查询
	 * @throws Exception
	 */
	@Override
	public List<Customer> findSome(String customerName,String customerLevel,
	                              String customerSource,String customerIndustry,int page,int size) throws Exception {
		//创建客户对象
		Customer customer = new Customer();
		if (customerName != null) {
			customer.setCustomerName(customerName);
		}
		if (customerLevel != null) {
			customer.setCustomerLevel(customerLevel);
		}
		if (customerSource != null) {
			customer.setCustomerSource(customerSource);
		}
		if (customerIndustry != null) {
			customer.setCustomerIndustry(customerIndustry);
		}
		/**
		 * //参数配置
		 * pageNum 页码值   pageSize  每页最大值
		 */
		PageHelper.startPage(page,size);
		//查询客户列表
		return customerDao.findSome(customer);
	}

	@Override
	public void save(Customer customer) throws Exception {
		customerDao.save(customer);
	}

	@Override
	public Customer findById(String id) throws Exception {
		return customerDao.findById(id);
	}

	@Override
	public void delete(String id) throws Exception {
		 customerDao.delete(id);
	}

	@Override
	public void update(Customer customer) throws Exception {
		customerDao.update(customer);
	}

	@Override
	public List<Customer> findAllCustomerAndLinkMan() throws Exception {
		return customerDao.findAllCustomerAndLinkMan();
	}

	@Override
	public Customer findCustomerById(String customerId) {
		return customerDao.findCustomerById(customerId);
	}

}
